import { defineComponent } from "@/shared/tools.mjs";

export const ngOnChildComponent = defineComponent({
  controller: class NgOnChildComponentCtrl {
    /**
     * @type {string[]}
     */
    static $inject = ["$scope", "$element"];

    /**
     * @param {ng.IScope} $scope
     * @param {[Element]} $element
     */
    constructor($scope, $element) {
      this.$scope = $scope;
      this.$element = $element;
    }

    hotEvent() {
      const event = new CustomEvent("customType", { detail: new Date() });
      this.$element[0].dispatchEvent(event);
    }

    handleClick() {
      console.log("NgOnChildComponentCtrl", this.$scope);
    }
  },
  controllerAs: "NgOnChildComponentCtrl",
  template: /* HTML */ html`
    <button ng-click="NgOnChildComponentCtrl.hotEvent()">Hot Event</button>
    ${DebugButtonHTML("NgOnChildComponentCtrl")}
  `,
});
